package com.jay.net.clazz;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class NetworkInterfaceCls {
	public static void main(String[] args) throws SocketException {
		Enumeration<?> e1 = (Enumeration<?>) NetworkInterface
				.getNetworkInterfaces();
		while (e1.hasMoreElements()) {
			NetworkInterface ni = (NetworkInterface) e1.nextElement();
			System.out.println(ni.getName());
			System.out.println(ni.getDisplayName());
			System.out.println(ni.getIndex());
			System.out.println(ni.getMTU());
			System.out.println(ni.getParent());
			System.out.println(ni.getName());
			System.out.println(ni.isLoopback());
			System.out.println(ni.isPointToPoint());
			System.out.println(ni.isUp());
			System.out.println(ni.isVirtual());
			System.out.println(ni.supportsMulticast());
			byte[] mac = ni.getHardwareAddress();
			for (int i = 0; i < mac.length; i++) {
				System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-"
						: "");
			}
			System.out.println();
			Enumeration<?> e2 = ni.getInetAddresses();
			while (e2.hasMoreElements()) {
				InetAddress ia = (InetAddress) e2.nextElement();
				if (ia instanceof Inet6Address) {
					System.out.println("IPv6 is " + ia.getHostAddress());
				} else {
					System.out.println("IPv4 is " + ia.getHostAddress());
				}
			}
			System.out.print("\n");
		}
	}
}
